#include <iostream>
#include <fstream>
#include <cstring>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>

#define MULTICAST_ADDR "239.0.0.1"
#define PORT 12345
#define BUFFER_SIZE 1024

int main() {
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(MULTICAST_ADDR);
    addr.sin_port = htons(PORT);

    std::ifstream file("large_file.dat", std::ios::binary);
    if (!file) {
        std::cerr << "Failed to open file" << std::endl;
        return 1;
    }

    char buffer[BUFFER_SIZE];
    while (file.read(buffer, BUFFER_SIZE)) {
        sendto(sockfd, buffer, BUFFER_SIZE, 0, (struct sockaddr*)&addr, sizeof(addr));
    }
    size_t remaining = file.gcount();
    if (remaining > 0) {
        sendto(sockfd, buffer, remaining, 0, (struct sockaddr*)&addr, sizeof(addr));
    }

    file.close();
    close(sockfd);
    return 0;
}    